<?php
/**
 * @Author: gml
 * @Date:   2015-11-24 13:20:53
 * @Last Modified by:   gml
 * @Last Modified time: 2016-11-07 11:56:24
 */
class My_Controller extends CI_Controller {
	public $output;
	public function __construct(){
		parent::__construct();
		$this -> checkLogin();
	}
	
	private function checkLogin() {
/*		$this->load->helper('url');
		if(strtolower($this -> uri -> segment(1)) == 'login') return false;

		if(empty($_SESSION['datacenter_account'])) {
			redirect('/Login/index');
			exit;
		}*/
	}

	public function render_json($obj, $status=200)
	{
		if ($status!=200)
			$this->output->set_status_header($status);

		$this->output->set_content_type('application/json');
		$this->output->set_output(json_encode($obj));
	}
}

function GUID()
{
	if (function_exists('com_create_guid') === true)
	{
		return trim(com_create_guid(), '{}');
	}

	return sprintf('%04X%04X%04X%04X%04X%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
}
 function map($var)
 {
	 if (is_numeric($var)) {
		 return intval($var);
	 } else {
		 return $var;
	 }
 }


function getMondayDiffDay($weekday)
{
	$diffDay = 0;
	switch ($weekday) {
		case 0:
			$diffDay = 6;
			break;
		case 1:
			$diffDay = 0;
			break;
		case 2:
			$diffDay = 1;
			break;
		case 3:
			$diffDay = 2;
			break;
		case 4:
			$diffDay = 3;
			break;
		case 5:
			$diffDay = 4;
			break;
		case 6:
			$diffDay = 5;
			break;
	}
	return $diffDay;
}

function getMonday($diff, $startDate)
{

	$newDate = '';
	if($diff != 0){
		$num = strtotime($startDate) - $diff*60*60*24;
		$newDate = date("Y-m-d", $num);
	}else{
		$newDate = $startDate;
	}
	// echo 'asha:'.$newDate; exit;
	return $newDate;
}


